import { program } from "commander";
import { loadUserConfig } from "./loadUserConfig";
import { createApp } from "../app/createApp";
import chalk from "chalk";
export function cli(ctx: { dirname: string }) {
    const { dirname } = ctx;
    program
        .command("deploy")
        .description("deploy your website to your server")
        .action(async () => {
            const config = await loadUserConfig(dirname);
            const app = createApp(config);

            try {
                await app.init();
                console.log(chalk.green("Deploy success!"));
            } catch (e) {
                app.spinner.fail("An error occurred: ");
                console.error(e);
            } finally {
                app.clear();
                process.exit(0);
            }
        });

    program.parse();
}
